<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
		<script src="../js/vue.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<body>
		<div id="test">
			ctime:{{ ctime }}
			<hr >
			格式化：{{ ctime | formattime }}
			<hr >
			ctime2:{{ ctime2 }}
			<hr >
			格式化：{{ ctime2 | formattime }}
		</div>
		<script>
			let vue = new Vue({
				el:'#test',
				data:{
					ctime:new Date(),
					ctime2:Date.now()
				},
				//局部过滤器
				filters:{
					formattime(time){
						var fommatedate =  new Date(time)
						var year = fommatedate.getFullYear()
						var month = fommatedate.getMonth()+1
						var day = fommatedate.getDate().toString()
						// console.log(typeof(day))
						// var date = fommatedate.getDate().toString().padStart(2,"0")
						var day = fommatedate.getDate().toString().padStart(2,'0')
			
						// console.log(date)
						//console.log(day.padStart(2,'0'))
						//.toString().padStart(2,'0')
						var hour = fommatedate.getHours()
						var min = fommatedate.getMinutes()
						var sec = fommatedate.getSeconds()
						datetime = `${year}-${month}-${day} ${hour}:${min}:${sec}`
						return datetime
					}
					
					
				}
			})
		</script>
	</body>
</html>
